package reflect;


import java.util.Scanner;

/**
 * 反射机制的对象实例化
 */
public class ReflectDemo2 {
    public static void main(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
        Person person = new Person();
        System.out.println(person);

        /*
        反射机制实例化
        1、获取对应类对象
        2、通过类对象的newInstance()方法实例化
         */
        //Class cls = Person.class;
        //Class cls = Class.forName("reflect.Person");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个类的完全限定名：");
        String className = scanner.nextLine();

        Class cls = Class.forName(className);
        System.out.println(cls);
        Object obj = cls.newInstance();
        System.out.println(obj);
    }
}
